package org.bigjava.controller;

import org.bigjava.bean.Compliant;
import org.bigjava.bean.Wuye;
import org.bigjava.biz.CompliantService;
import org.bigjava.biz.WuyeService;
import org.bigjava.common.Constant;
import org.bigjava.common.FenYe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CompliantController {

    @Autowired
    HttpSession session;

    @Autowired
    CompliantService compliantService;
    @Autowired
    WuyeService wuyeService;

    //跳转到投诉页面(获得物业列表)
    @RequestMapping("compliant/tj")
    public String complianttj(){
        List<Wuye> wuyes = wuyeService.wuYeQuan();
        session.setAttribute("wuyes",wuyes);
        return "complianttj";
    }
    //投诉
    @RequestMapping("compliant/tianjia")
    public String compliantAdd(Compliant compliant){
        compliantService.compliantAdd(compliant);
        return "redirect:/compliant/fenye";
    }
    //处理投诉信息
    @RequestMapping("compliant/xg")
    public String compliantChuLi(int id){
        compliantService.compliantChuLi(id);
        Object a = session.getAttribute("yeshu");
        return "redirect:/compliant/fenye?a="+a;
    }

    //根据物业公司或者投诉人查询投诉信息
    @RequestMapping("compliant/sousuo")
    public String compliantSouSuo(String dyg,String deg){
        if(dyg==""){dyg = "0";}
        if(deg==""){deg = null;}
        int w_id  = Integer.parseInt(dyg);
        List<Compliant> lists = compliantService.compliantSouSuo(w_id,deg);
        session.setAttribute("compliants",lists);
        return "compliantgl";
    }

    //删除投诉
    @RequestMapping("compliant/shanchu")
    public String compliantShanChu(int id){
        compliantService.compliantShanChu(id);
        Object a = session.getAttribute("yeshu");
        return "redirect:/compliant/fenye?a="+a;
    }

    //分页查询出投诉信息
    @RequestMapping("compliant/fenye")
    public String compliantFenYe(String a){
        List<Wuye> wuyes = wuyeService.wuYeQuan();
        session.setAttribute("wuyes",wuyes);
        //业主总人数
        int zong =  compliantService.compliantZong();
        session.setAttribute("zong",zong);
        //调用分页方法返回下一页开始id
        int ks = FenYe.fenYe(session,zong,a, Constant.fenye);
        //分页查询出的业主
        List<Compliant> lists = compliantService.compliantFenYe(ks,Constant.fenye);
        session.setAttribute("compliants",lists);
        return "compliantgl";
    }
}
